package _17_剑指Offer;

import java.util.Queue;
import java.util.Stack;

/**
 *  对于实现最小栈思路
 *       只要保证栈元素的偏序顺序，其他元素可以不用管
 *       栈元素入栈，那么比较最小栈元素，最小栈元素表示栈前n项的最小元素
 */
public class _30_剑指Offer包含min函数的栈 {

    private final Stack<Integer> stack = new Stack<>();

    private final Stack<Integer> minStack = new Stack<>();


    /** initialize your data structure here. */
    public _30_剑指Offer包含min函数的栈() {

    }

    public void push(int x) {
        if (minStack.isEmpty() || minStack.peek() >= x) {
            minStack.push(x);
        }
        stack.push(x);
    }

    public void pop() {
        if (stack.pop().equals(minStack.peek())) {
            minStack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return minStack.peek();
    }

}
